package com.example.lean;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
    ListView list;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview1layout);
        list = (ListView) findViewById(R.id.ListView01);
        /*
        //动态绑定数据
        //定义数组
        String[] data = {
                "企业会话",
                "办公邮件",
                "财务信息查询",
        };
        //为ListView设置数组适配器ArrayAdapter
        list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data));
         */
        //为ListView设置列表选项监听器
        list.setOnItemClickListener(this);
    }

    //定义列表选项监听器的事件
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(this, "您选择的项目是："
                + ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
    }
}